package menu;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;


/**
 * Cascading Menu design pattern.
 * An example midlet that uses Cascading Menu pattern.
 *
 * @author Ben Hui
 */

public class Menulet extends MIDlet {
  static Menulet instance;
  MenuList menulist = null;

  /** Constructor */
  public Menulet() {
    instance = this;
  }

  /** Main method */
  public void startApp() {

    // initialize MenuList with Display object
    menulist = new MenuList( Display.getDisplay(this) );

    // create three menus
    // use MenuElement for a menu container and
    // use MenuElement also for menu item in the container
    // link each menu item to a sample MDisplayable
    MenuElement menu3 = new MenuElement( "Attractions" );
    menu3.addChild( new MenuElement( "Museum"), new SampleMenuAction() );
    menu3.addChild( new MenuElement( "Art Galleries"), new SampleMenuAction() );
    menu3.addChild( new MenuElement( "Exhibitions"), new SampleMenuAction() );

    MenuElement menu2 = new MenuElement( "Restaurants" );
    menu2.addChild( new MenuElement( "Bakeries"), new SampleMenuAction() );
    menu2.addChild( new MenuElement( "Coffee Shop"), new SampleMenuAction() );
    menu2.addChild( new MenuElement( "Diner"), new SampleMenuAction() );

    MenuElement menu1 = new MenuElement( "Shops" );
    menu1.addChild( new MenuElement( "Automotives"), new SampleMenuAction() );
    menu1.addChild( new MenuElement( "Books"), new SampleMenuAction() );
    menu1.addChild( new MenuElement( "Fashions"), new SampleMenuAction() );

    // create the main menu,
    // and link the menu item to the menu containers create above
    MenuElement main = new MenuElement( "Main Menu" );
    main.addChild( new MenuElement( "Shops"), menu1 );
    main.addChild( new MenuElement( "Restaurants"), menu2 );
    main.addChild( new MenuElement( "Attractions"), menu3 );

    // show the main menu, this will make the main menu as the current screen
    menulist.showMenu( main );
  }

  /** Handle pausing the MIDlet */
  public void pauseApp() {
  }

  /** Handle destroying the MIDlet */
  public void destroyApp(boolean unconditional) {
  }

  /** Quit the MIDlet */
  public static void quitApp() {
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance = null;
  }

}
